import { get, post, remove, put } from '@/server/request'
import { baseApi, RequestCode } from '@/server/base'
import axios from 'axios';

export const Collection = {
  /**
   * 查询数据
   * @param params 
   * @returns 
   */
  imageCollection(projectName: string, type: '' | '1' | '2' | '3', projectId?: string,) {
    return get(`${baseApi}/photoList/getByProject`, { photoName, type, id: projectId });
  },

  /**
   * 创建图片集
   */
  saveImageCollection(params: {
    name: string,//	图集名称		true
    projectId: string | number,//	项目id		true
    projectName: string,//	项目名称		true
    type: string,//	项目类
  }) {
    return post(`${baseApi}/photoList/save`, params);
  },
  /**
   * 删除图片集
   */
  deleteImageCollection(photoListId: number) {
    return remove(`${baseApi}/photoList/delete/${photoListId}`);
  },
  /**
   * 保存任务
   * @param params
   * @returns 
   */
  saveImageTask(params: {
    annotationEndTime: string, //标注截止日期
    annotationTeamId: number, //标注团队id
    clearEndTime: string, //清洗截止日期
    clearTeamId: number, //清洗团队id
    creatorId: number, //创建者id
    dataType: string, //数据类型
    doDelete: number, //成员能否删除图片（0不可，1可以）
    name: string, //任务名称
    photoListId: number, //数据集id
    reviewEndTime: string, //审核截止日期
    reviewTeamId: number, //审核团队id
    samplingRatio: number, //抽检比例
  }) {
    return post(`${baseApi}/task/save`, params);
  },

  /**
   * 图片集上传
   * @param params 
   * @returns 
   */
  saveUploadPhoto(params: any) {
    //使用 原生的制定格式进行图片上传
    const url = `${baseApi}/image/upload/${params.photoListId}`;
    const { file, ..._params } = params;
    let data = new FormData();
    Object.keys(_params).map((key: string) => {
      data.set(key, params[key]);
    })
    file.map((_file: any) => {
      data.append('file', _file.raw, _file.name);
    })

    const config = { headers: { 'Content-type': 'multipart/form-data' } };
    return axios.post(url, data, config);
    // return post(`${baseApi}/image/upload/${params.photoListId}`, params);
  }

}
